package xyz.wangdanhua.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.Api;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.text.SimpleDateFormat;

/**
 * SwaggerConfig
 *
 * @author W.J.H.7
 * @since 0.1
 */
@Configuration
//@EnableSwagger2
//@Component
//@ComponentScan(basePackages = "xyz.wangdanhua.controller")
public class SwaggerConfig {

  @Bean()
  public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE);
    return mapper;
  }

//  @Bean
//  public Docket api() {
//    return new Docket(DocumentationType.SWAGGER_2).select()
//        .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)).paths(PathSelectors.any())
//        .build().apiInfo(apiInfo());
//  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("Venus REST Application").description("千帆订购服务接口")
        .version("0.2").build();
  }
}